package com.dmjy.boot.common.formatter;

import com.dmjy.boot.common.util.DateUtil;

import java.text.FieldPosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 支持多种时间格式转换
 *
 * @author 敖癸
 * @formatter:on
 * @since 2022/11/4
 */
public class MultiDateFormat extends SimpleDateFormat {


    private static final Locale locale = Locale.CHINA;

    @Override
    public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", locale).format(date, toAppendTo, fieldPosition);
    }

    @Override
    public Date parse(String source) {
        return DateUtil.parse(source);
    }

}
